/** 足迹列表功能模块 */
export const loduleMixin = {
	data() {
		return {
			listData: [],
			listDataPage: 1,
			listDataTotal: 0,
			listDataAfresh: false,
			listDataLoading: true,
			listDataEmpty: false,
			listDataRequestStart: false, // 请求开始
			listDataResetTimer: null,
		}
	},
	onPullDownRefresh() { this.resetlistData(); },
	onReachBottom() { this.listDataLoading && this.getlistData(); },
	onLoad() { this.getlistData(); },
	methods: {
		/** 重新获取足迹列表列表 */
		resetlistData() {
			this.listDataAfresh = true;
			this.listDataLoading = true;
			this.listDataEmpty = false;
			this.listDataRequestStart = false;
			clearTimeout(this.listDataResetTimer);
			this.listDataResetTimer = setTimeout(() => this.getlistData(), 300);
		},
		/** 获取足迹列表列表执行 */
		async getlistData() {
			if (this.listDataRequestStart) return;
			this.listDataRequestStart = true;
			if (this.listDataAfresh) this.listDataPage = 1;
			try {
				var res = await this.$post('6551cfe69bcf3', {
					page: this.listDataPage,
					listData_rows: 32,
					// 其他参数
				});
				const _listData = (res.data.data || []).map((t, i) => {
					return {
						...t,
						animationTime: i / 10 + 0.25,
						goods: t.goods_list.map(item => {
							return {
								...item,
								goods_thumb: item.thumb,
								goods_shop_price: item.shop_price,
								aid: item.id,
							}
						})
					}
				})
				if (this.listDataAfresh) this.listData = _listData;
				else this.listData = this.listData.concat(_listData);
				this.listDataPage++;
				this.listDataTotal = res.data.total;
				this.listDataLoading = this.listData.length < this.listDataTotal;
			} catch (e) { this.listDataLoading = false; }
			this.listDataAfresh = false;
			uni.stopPullDownRefresh();
			this.listDataRequestStart = false;
			this.listDataEmpty = !this.listData.length && !this.listDataLoading;
		},
	}
};